package com.fmn.dots_final_i_hope;

import model.Player;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.widget.Toast;

public class GameDialogs {

	public static void showEndGameDialog(Context context,
			final Activity activity) {
		AlertDialog.Builder dBuilder = new AlertDialog.Builder(context);

		String msg = PlayerControl.anounceWinner() + "\nPoints: "
				+ PlayerControl.p1.getCurrentPoints() + " : "
				+ PlayerControl.p2.getCurrentPoints();

		dBuilder.setTitle("GAME OVER");
		dBuilder.setMessage(msg);

		dBuilder.setNegativeButton("REMATCH",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						PlayerControl.nullStaticVariables();
						Intent rematchIntent = new Intent(activity, activity
								.getClass());
						activity.finish();
						activity.startActivity(rematchIntent);
					}
				});

		dBuilder.setPositiveButton("MAIN MENU",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						PlayerControl.nullStaticVariables();

						activity.finish();
					}
				});

		AlertDialog endGameDialog = dBuilder.create();
		endGameDialog.show();
	}

	
	public static void showDoYouSurrenderDialog(Context context,
			final Activity activity) {

		AlertDialog.Builder dBuilder = new AlertDialog.Builder(context);
		String msg = PlayerControl.getCurrentPlayer().getName()
				+ " are you sure you want to surrender? ";

		dBuilder.setTitle("SURRENDER ?");
		dBuilder.setMessage(msg);

		dBuilder.setNegativeButton("NO", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {

			}
		});

		dBuilder.setPositiveButton("YES",
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						PlayerControl.nullStaticVariables();
						activity.finish();
					}
				});

		AlertDialog endGameDialog = dBuilder.create();
		endGameDialog.show();
	}

	
//	public static void showTableSizeDialog(final Context context) {
//
//		AlertDialog.Builder dialoBuilder = new AlertDialog.Builder(context);
//		final String[] sizes = { "3/3", "3/4", "4/4", "4/5", "5/5" };
//		dialoBuilder.setTitle("Set Table Size");
//		dialoBuilder.setItems(sizes, new DialogInterface.OnClickListener() {
//
//			@Override
//			public void onClick(DialogInterface dialog, int which) {
//
//				Toast.makeText(context, sizes[which], Toast.LENGTH_SHORT)
//						.show();
//
//				if (sizes[which] == "3/3") {
//					PlayerControl.choosenCol = 3;
//					PlayerControl.choosenRow = 3;
//
//				} else if (sizes[which] == "3/4") {
//					PlayerControl.choosenCol = 4;
//					PlayerControl.choosenRow = 3;
//
//				} else if (sizes[which] == "4/4") {
//					PlayerControl.choosenCol = 4;
//					PlayerControl.choosenRow = 4;
//
//				} else if (sizes[which] == "4/5") {
//					PlayerControl.choosenCol = 5;
//					PlayerControl.choosenRow = 4;
//
//				} else if (sizes[which] == "5/5") {
//					PlayerControl.choosenCol = 5;
//					PlayerControl.choosenRow = 5;
//				}
//			}
//		});
//		AlertDialog alertDialog = dialoBuilder.create();
//		alertDialog.show();
//	}
	

	public static void showPlayerColorDialog(final Context context,
			final Player p) {

		AlertDialog.Builder dialoBuilder = new AlertDialog.Builder(context);
		final String[] sizes = { "GREEN", "PINK", "PURPLE", "ORANGE", "SILVER",
				"RED" };
		dialoBuilder.setTitle("Player 1 choose your color");
		dialoBuilder.setItems(sizes, new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {

				Toast.makeText(context,
						p.getName() + " is with " + sizes[which],
						Toast.LENGTH_SHORT).show();

				if (sizes[which] == "GREEN") {
					p.setChosenImage(R.drawable.taken_square1);

				} else if (sizes[which] == "PINK") {
					p.setChosenImage(R.drawable.taken_square2);

				} else if (sizes[which] == "PURPLE") {
					p.setChosenImage(R.drawable.taken_square3);

				} else if (sizes[which] == "ORANGE") {
					p.setChosenImage(R.drawable.taken_square4);

				} else if (sizes[which] == "SILVER") {
					p.setChosenImage(R.drawable.taken_square5);

				} else if (sizes[which] == "RED") {
					p.setChosenImage(R.drawable.taken_square6);
					
				}
			}
		});
		AlertDialog alertDialog = dialoBuilder.create();
		alertDialog.show();
	}

}
